package com.wngbms;

public class _11 {

    public static void main(String[] args) {
        int[] height = {1, 8, 6, 2, 5, 4, 8, 3, 7};
//        int[] height = {1, 1};

        System.out.println(res(height));
    }

    public static int res(int[] height) {
        if (height == null || height.length < 2) {
            return 0;
        }

        int i = 0, j = height.length - 1;
        int maxStore = 0;

        while (true) {
            int currStore = Math.min(height[i], height[j]) * (j - i);
            if (currStore > maxStore) {
                maxStore = currStore;
            }

            if (i >= j) {
                break;
            }

            if (height[i] < height[j]) {
                i++;
            } else {
                j--;
            }
        }
        return maxStore;
    }
}
